﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace TestWebApi.Controllers
{
    public class ValuesController : ApiController
    {
        static ValuesController()
        {
            Items = new Dictionary<int, string>();
            Items.Add(1, "1");
            Items.Add(2, "2");
        }

        public static Dictionary<int, string> Items;

        // GET api/values
        public IEnumerable<string> Get()
        {
            return Items.Values;
        }

        // GET api/values/5
        public string Get(int id)
        {
            return Items.ContainsKey(id) ? Items[id] : null;
        }

        // POST api/values
        public void Post([FromBody]int id, [FromBody]string value)
        {
            Items.Add(id, value);
        }

        // PUT api/values/5
        public void Put([FromBody]int id, [FromBody]string value)
        {
            Items[id] = value;
        }

        // DELETE api/values/5
        public void Delete(int id)
        {
            Items.Remove(id);
        }
    }
}